from django.contrib.syndication.views import Feed
from django.shortcuts import reverse
from django.utils.feedgenerator import Rss201rev2Feed, Atom1Feed

from article.models import Article


class BlogRssFeed(Feed):
    """
    rss订阅，仅显示文章摘要
    """
    feed_type = Rss201rev2Feed
    title = "songs126's django blog"
    description = 'songs126的博客文章订阅'
    link = '/'

    # rss显示内容
    def items(self):
        return Article.objects.all()

    # 订阅标题
    def item_title(self, item):
        return item.title

    # 订阅摘要
    def item_description(self, item):
        return item.digest

    # 订阅链接
    def item_link(self, item):
        return reverse('article:detail', args=(item.pk,))


class BlogAtomFeed(BlogRssFeed):
    """Atom子类"""
    feed_type = Atom1Feed
    subtitle = BlogRssFeed.description
    